package ar.com.photo_admin.domain

class UserAlbumAccess {

	User user
	
	EventAlbum album
	
	static belongsTo = [user:User, album:EventAlbum]
	
    static constraints = {
    }
	
	static UserAlbumAccess link(user, album) {
		def m = UserAlbumAccess.findByUserAndAlbum(user, album)
		if (!m) {
			m = new UserAlbumAccess()
			user?.addToUserAlbumAccesses(m)
			album?.addToUserAlbumAccesses(m)
			m.save()
		}
		
		return m
	}
	
	static void unlink(user, album) {
		def m = UserAlbumAccess.findByUserAndAlbum(user, album)
		if (m) {
			user?.removeFromUserAlbumAccesses(m)
			album?.removeFromUserAlbumAccesses(m)
			m.delete()
		}
	}
}
